/***************************************************************************
 *   Copyright (C) 2011  by TinySofts                                      *
 *   tinysofts@gmail.com                                                   *
 *   All Rights Reserved.                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   Refer to http://code.google.com/p/tinydict/                           *
 ***************************************************************************/

/*
    Main Function
    Status:Open;ReleaseReady;L
*/

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "tdict.h"

Q_IMPORT_PLUGIN(qsqlite)
Q_IMPORT_PLUGIN(qcncodecs)

int main(int argc, char *argv[])
{
   
    QApplication a(argc, argv);

    /*run one instance only*/
    QSystemSemaphore sema("TinySoft.C.RUNONE.SEMA",1,
                          QSystemSemaphore::Open);
    sema.acquire();
    QSharedMemory mem("TinyDict.by.TinySoft.RUNONE");
    if (!mem.create(1))
    { 
        sema.release();    
        return 0; 
    } 
    sema.release();

    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTranslator translator;
    translator.load("tinydict.zh");
    a.installTranslator(&translator);

    MainWindow w;
    if(argc>1) {
        if(strcmp(argv[1],"-config")==0)
            w.initConfig();
        else if(strcmp(argv[1],"-dictinfo")==0)
            w.clearDictInfo();
        else if(strcmp(argv[1],"-babylon")==0)
            w.initBabylonDicts();
    }
    w.resize(550,400);
    w.show();

    //QApplication::setQuitOnLastWindowClosed(false);

    return a.exec();
}
